//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.aidong.web.controller.member;

import com.aidong.dao.base.ConditionMap;
import com.aidong.dao.base.OrderSet;
import com.aidong.dao.base.Pagination;
import com.aidong.dao.wills.ContractSignDao;
import com.aidong.dao.wills.MemberContractDao;
import com.aidong.model.wills.ContractSign;
import com.aidong.web.controller.BaseController;
import com.aidong.web.controller.svc.ContractSignController;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping({"contractSignConfirm"})
public class ContractSignConfirmController extends BaseController {
    @Resource
    MemberContractDao memberContractDao;
    @Resource
    ContractSignDao contractSignDao;

    public ContractSignConfirmController() {
    }

    @RequestMapping({"list"})
    public ModelAndView list() {
        return (new ModelAndView("member/sign/list")).addObject("contractType", this.getTypeList("signContractType")).addObject("signStatus", this.getTypeList("signStatus"));
    }

    @RequestMapping({"_list"})
    public ModelAndView _list(@RequestParam(value = "shopCode",required = false) String shopCode, @RequestParam(value = "status",required = false) Integer status, @RequestParam(value = "contractType",required = false) String contractType, @RequestParam(value = "contractCode",required = false) String contractCode, @RequestParam(value = "name",required = false) String name, @RequestParam(value = "salesCode",required = false) String salesCode, @RequestParam(value = "dateFrom",required = false) String dateFrom, @RequestParam(value = "dateTo",required = false) String dateTo, @RequestParam(value = "pageNo",required = false) String pageNo, @RequestParam(value = "totalCount",required = false) String totalCount) {
        Pagination pg = new Pagination(1, 20);
        pg.setPage(this.parseInt(pageNo), this.parseInt(totalCount));
        ConditionMap cd = new ConditionMap();
        this.addConditionShopCode(cd, "shopCode", shopCode);
        cd.eq("status", status);
        cd.eq("contractCode", contractCode);
        cd.eq("contractType", contractType);
        ConditionMap mv;
        if(!this.chkNull(salesCode)) {
            mv = new ConditionMap(1);
            mv.eq("salesCode", salesCode);
            mv.eq("salesCode2", salesCode);
            cd.addSub(mv);
        }

        if(!this.chkNull(name)) {
            mv = new ConditionMap(1);
            mv.like("memberCode", "%" + name + "%");
            mv.like("memberName", "%" + name + "%");
            cd.addSub(mv);
        }

        this.contractSignDao.queryPageList(pg, cd, (new OrderSet()).desc("updateTime"));
        ModelAndView mv1 = new ModelAndView("member/sign/_list");
        mv1.addObject("list", pg.getResultList());
        mv1.addObject("pg", pg);
        return mv1;
    }

    @RequestMapping({"confirm"})
    public ModelAndView confirm(@RequestParam("id") int id) {
        ContractSign sign = (ContractSign)this.contractSignDao.getById(Integer.valueOf(id));
        if(sign == null) {
            return this.showAlert("合同号错误!");
        } else {
            sign.setAuthCode(ContractSignController.getAuthCode(new String[]{sign.getContractCode(), sign.getContractType()}));
            ModelAndView mv = new ModelAndView("member/sign/confirm");
            mv.addObject("sign", sign);
            return mv;
        }
    }

    @RequestMapping({"_confirm"})
    @ResponseBody
    public String _confirm(@RequestParam("id") int id, @RequestParam("op") String op) {
        ContractSign sign = (ContractSign)this.contractSignDao.getById(Integer.valueOf(id));
        if(sign == null) {
            return this.getResult(false, "合同号错误!");
        } else if(sign.getStatus().intValue() != 2) {
            return this.getResult(false, "不能操作!");
        } else if(!this.chkNull(op) && ("1".equals(op) || "2".equals(op))) {
            if("2".equals(op)) {
                try {
                    this.contractSignDao.updateStatus(sign.getAutoId().intValue(), 4);
                    this.addUserLog("退回" + this.cache.getValue("signContractType", sign.getContractType()) + "签名", "合同号:" + sign.getContractCode());
                } catch (Exception var6) {
                    this.log.error("back contractsign", var6);
                    return this.getResult(false, "操作发生错误");
                }
            } else {
                try {
                    this.contractSignDao.updateConfirm(sign, this.getLoginUserCode());
                    this.addUserLog("确认" + this.cache.getValue("signContractType", sign.getContractType()) + "签名", "合同号:" + sign.getContractCode());
                } catch (Exception var5) {
                    this.log.error("confirm contractsign", var5);
                    return this.getResult(false, "操作发生错误");
                }
            }

            return this.getResult(true, "操作成功");
        } else {
            return this.getResult(false, "操作类型错误!");
        }
    }
}
